import { configureStore } from '@reduxjs/toolkit'
import discoverReducer from './modules/discover'
import audioReducer from './modules/audio'
import songDetail from './modules/song'
import options from './modules/options'
import user from './modules/user'
import {
  useSelector,
  useDispatch,
  TypedUseSelectorHook,
  shallowEqual,
} from 'react-redux'

const store = configureStore({
  reducer: {
    discover: discoverReducer,
    audio: audioReducer,
    songDetail: songDetail,
    options: options,
    user: user,
  }
})

type GetStateFnType = typeof store.getState
type IRootState = ReturnType<GetStateFnType>
type DispatchType = typeof store.dispatch

export const useAppSelector: TypedUseSelectorHook<IRootState> = useSelector
export const useAppDispatch: () => DispatchType = useDispatch
export const shallowEqualApp = shallowEqual

export default store
